-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dev/black #3840
Dev/black #3840
Conversation
Thanks for working on the actions. We have some large PRs and branches pending and need to get to a point where we can freeze PRs, merge all the big kahunas, and only then can we do a massive formatting sweep. We've been waiting for months to do this but there was way too much changing to break history with a bit format PR. I believe we settled on base black config but with line length of 100 or 120. |
@psychedelicious No worries, I totally get that. I personally find it harder to expand on existing files right now because I have to turn off my auto formaters, but that’s me. Just say the word when you want to pull the trigger. Git makes it look harder than it really is to make this branch mergable. Basically it’s as easy as copying all the files from main and running black on them. No need to actually work out merge conflicts. |
I hear you, I disabled my autoformat on save too 😮💨 the concern was more that with a big formatting commit, we create a boundary that makes diffs hard to reason about, and the code was in very high flux. Getting close now! |
Is there a reason you want to do 100-120 character lines? I always liked the standard 88 (leaving an 8 character buffer from the classic 80). |
Our monitors are generally bigger than punchcards or hardware terminals now (excellent talk btw), though of course it's just a preference. The frontend code will be getting the 100 or 120 width treatment soon too |
Yeah, I totally get the issue with one big commit that reformats the whole code base and creates a diff wall. If you want, I’ll happily break it up into individual files if that helps. Especially if we can identify files that are not being changed right now. I just didn’t want to spam you with PR’s without first discussing. |
I believe we are pretty close to enabling the formatting but I'll request @ebr and @brandonrising for their opinions |
I actually did the "reformat everything with black" thing last winter during the 2.3 release and one of the gotchas was that "git blame" ended up blaming me for every line of code in the repository. After some searching I found a technique that preserves blame across the black boundary, applied it, and it improved the situation. Do you know about it? If not, I'll try to retrace my steps. |
I prefer the longer lines. 100 is pretty comfortable for me. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is great but I'd like to wait on this until the pace of change slows down. About a week, I'd say.
@lstein there’s something here about how to get around the git blame issue: I’m not entirely clear on how it works based on this link alone, but maybe one big squash merge and then add the commit hash to ‘.git-blame-ignore-revs’? |
pip install .[test] | ||
|
||
# - run: isort --check-only . | ||
- run: black --check . |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since you're using pre-commit, may I recommend the following action instead:
- uses: pre-commit/action@v3.0.0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is pretty cool. I did not know this existed. Personally I'm a little torn on using it because there's not much gained by using it and it leaves us dependent on an externally managed action. There's also a slight difference in what is being run in the precommit hooks right now. For the sake of speed, they only run black on what is being committed, while the current GHA is running black on everything.
If others prefer using this action, though, I don't feel super strongly about it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not a dev here, so please remember that I cannot speak for the project at all :-). I understand what you're saying about external actions, although it is pretty official. Perhaps at least run pre-commit run -a
instead of black directly? It reduces the chance that at some point someone might want to change a parameter or something and will need to remember to sync in both places.
IIRC, I think the action it can also be configured to add comments with places that were missed if you pass a token (but possibly not on a PR from a fork). It also includes a git diff
after it runs, so instead of just a binary "failed", you can see what it fixed, which can be helpful for new contributors who aren't aware of the coding conventions.
8d0f5ca
to
7880318
Compare
My 2 cents:
|
@zopieux - Actually by running black with the pre-commit hooks only, black would only be applied to the files changed in the given commit. |
I'm calling this out on discord to hopefully grab everyone's attention (and any strongly-dissenting opinions). This will also close #2522. |
080e252
to
f24f053
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we update this to 120 characters? If we can, I think there is no reason not to get this merged in today @ebr @brandonrising
Do it! Just be careful to use the blame-skip trick
…On Thu, Jul 27, 2023 at 9:16 AM Kent Keirsey ***@***.***> wrote:
***@***.**** commented on this pull request.
Can we update this to 120 characters? If we can, I think there is no
reason not to get this merged in today @ebr <https://github.com/ebr>
@brandonrising <https://github.com/brandonrising>
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lillekemiker could I ask you to please rebase on current state of main
, apply the 120 char line length change, and force-push one more time? I will make sure this is reviewed today and will try to merge ASAP.
After this goes in, the owners of all open PRs will need to manually
black-ify and push their branches using the correct line length. They won't
have access to the updated `pyproject.toml` so it'll have to be done
manually. Aside from line length, are there any other non-default settings
we should be aware of? It would be helpful to put the appropriate black
config file directives into a comment here for quick reference.
Also, what's the most efficient way of resolving the conflicts that have already accumulated? Perhaps we need another PR off of main for the formatting changes, and then apply this one to get the pre-commit hooks and pyproject settings.
|
Any in-flight PRs would have to apply There are also a couple of other options, e.g. Re: conflict resolution - @lillekemiker just force-pushed the latest changes, so I will make sure to review it ASAP so we can merge it before any more conflicts are introduced. I will add a commit with the blame-skip trick. |
Done! |
Nevermind - not an issue with the latest |
@lillekemiker did you have to pass |
I found that if I run black using |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
🚨 I will add added another commit into .git-blame-ignore-revs
before merging. Suggest we merge this as a rebase rather than a squash or merge commit, such that the SHA of the black
commit remains unchanged.
@lstein - any current in-flight PRs will need to pip install black
followed by black --line-length 120 .
(also @Millu please take note). But I don't think we can avoid conflict resolution entirely.
Please approve, and we'll merge if this is acceptable.
also remove lib/ from gitignore as it is hiding the installer code from 'black'
Both a rebase and a squash will change the SHA. Only a merge commit, or another PR with the SHA of the squash or rebased commit. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
right, good point. Let's try a merge commit, though it means the |
Let's go! Can finally hack on that codebase :-) |
What type of PR is this? (check all applicable)
Have you discussed this change with the InvokeAI team?
Description
Introducing black to the code base as a first step towards this:
https://github.com/invoke-ai/InvokeAI/discussions/3721
Related Tickets & Documents
QA Instructions, Screenshots, Recordings
Added/updated tests?
[optional] Are there any post deployment tasks we need to perform?
All active branches will be affected by this and will need to be updated.
This PR adds a new github workflow for black as well as config for pre-commit hooks to those who wish to use it